#include "ecb_mode.h"

int C_ECB_MODE::Encrypt(BYTE* pIn, int iLenIn, BYTE* pOut, int* piLenOut, IBlockCipherKernel* pobjKer)
{
    int iBlock  = pobjKer->GetBlockLen();
    int& iWrite = *piLenOut;

    iWrite = 0;
    while(iWrite + iBlock <= iLenIn)
    {
        pobjKer->Encrypt(pIn + iWrite, pOut + iWrite);
        iWrite += iBlock;
    }

    return 0;
}

int C_ECB_MODE::Decrypt(BYTE* pIn, int iLenIn, BYTE* pOut, int* piLenOut, IBlockCipherKernel* pobjKer)
{
    int iBlock  = pobjKer->GetBlockLen();
    int& iWrite = *piLenOut;

    iWrite = 0;
    while(iWrite + iBlock <= iLenIn)
    {
        pobjKer->Decrypt(pIn + iWrite, pOut + iWrite);
        iWrite += iBlock;
    }

    return 0;
}

int C_IV16_MODE::GetIV(BYTE* data, int* piLen)
{
    memcpy(data, m_bfIV, 16);
    if(piLen) *piLen = 16;
    return 0;
}

int C_IV16_MODE::SetIV(BYTE* data, int iLen)
{
    memcpy(m_bfIV, data, 16);
    return 0;
}